var express = require('express');
var router = express.Router();
const MusicControl = require("../control/MusicControl")
const multer = require("multer")
const path = require("path")
//自定义存储
const storage = multer.diskStorage({
    //自定义存储位置
    destination: function (req, res, cb) {
        cb(null, 'public/media/music')
    },
    //文件名字
    filename: function (req, file, cb) {
        const uniquFilename = Date.now() + '-' + Math.round(Math.random() * 1E9)
        //获取后缀
        const ext = path.extname(file.originalname)
        cb(null, uniquFilename + ext)
    }
})
const upload_music = multer({ storage: storage })
router.post('/', upload_music.single("file"), MusicControl.add_music)
router.post('/doc', MusicControl.add_music_document)
router.get('/:id', MusicControl.get_list)
router.put('/', MusicControl.put_music)
router.delete('/:id', MusicControl.delete_music)
module.exports = router
